package com.windea.study.kotlin.game.tankwar2.model

import com.windea.study.kotlin.game.tankwar2.*
import com.windea.study.kotlin.game.tankwar2.core.*
import com.windea.study.kotlin.game.tankwar2.enums.*
import com.windea.study.kotlin.game.tankwar2.interfaces.*

/**我方坦克。*/
class PlayerTank(
	x: Int,
	y: Int
) : Tank(x, y) {
	//当方向改变时，意味着玩家将会移动
	override var direction: Direction = Direction.Up
	override val speed: Int = 8
	override var health: Int = 20
	
	override fun draw() {
		//根据坦克的方向进行绘制
		Painter.drawImage(when(direction) {
			Direction.Up -> "img/tank_u.gif"
			Direction.Down -> "img/tank_d.gif"
			Direction.Left -> "img/tank_l.gif"
			Direction.Right -> "img/tank_r.gif"
		}, x, y)
	}
	
	override fun onSuffer(other: Attackable, entities: MutableList<Entity>) {
		if(GameConfig.debugMode) return
		
		super.onSuffer(other, entities)
	}
	
	fun attack(entities: MutableList<Entity>) {
		entities += Bullet(this, direction)
	}
	
	override fun move(nextDirection: Direction, entities: MutableList<Entity>) {
		//判断是否是往要碰撞的方向走
		if(nextDirection == badDirection) return
		
		//当前的方向，和希望移动的方向不一致时，只做方向改变
		if(nextDirection != direction) {
			direction = nextDirection
			return
		}
		
		super.move(nextDirection, entities)
	}
}
